﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CloudSoft.Extensions;

namespace ERPStore.Extensions
{
	// Todo : Move it to Localizable plugin
	public static partial class ModelsExtensions
	{
		/// <summary>
		/// Localizes the specified product.
		/// </summary>
		/// <param name="product">The product.</param>
		/// <param name="language">The language.</param>
		/// <param name="propertyName">Name of the property.</param>
		/// <returns></returns>
		public static string Localize(this Models.Product product, Models.Language language, string propertyName)
		{
			var localization = product.LocalizationList.SingleOrDefault(i => i.Language == language && i.PropertyName.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase));
			if (localization != null)
			{
				return localization.Value;
			}
			return product.GetPropertyValue(propertyName).ToString();
		}

		public static string GetLocalizedName(this Models.OrderStatus orderStatus)
		{
			switch (orderStatus)
			{
				case ERPStore.Models.OrderStatus.WaitingPayment:
					return "En attente de règlement";
				case ERPStore.Models.OrderStatus.PaymentAccepted:
					return "Règlement reçu, en attente de livraison";
				case ERPStore.Models.OrderStatus.PartialyDelivered:
					return "En cours de livraison partielle";
				case ERPStore.Models.OrderStatus.Delivered:
					return "Commande livrée";
				case ERPStore.Models.OrderStatus.Invoiced:
					return "Commande livrée et facturée";
				case ERPStore.Models.OrderStatus.WaitingProcess:
					return "En attente de livraison";
				default:
					return "A definir";
			}
		}

		public static string GetLocalizedName(this Models.UserPresentation presentation)
		{
			switch (presentation)
			{
				case ERPStore.Models.UserPresentation.Unkwnon:
					return string.Empty;
				case ERPStore.Models.UserPresentation.Mister:
					return "M";
				case ERPStore.Models.UserPresentation.Miss:
					return "Mme";
				case ERPStore.Models.UserPresentation.Misses:
					return "Mlle";
				default:
					return string.Empty;
			}
		}

		public static string GetLocalizedName(this bool condition)
		{
			if (condition)
			{
				return "Vrai";
			}
			else
			{
				return "Faux";
			}
		}

		public static string GetLocalizedName(this Models.CancelQuoteReason reason)
		{
			switch (reason)
			{
				case ERPStore.Models.CancelQuoteReason.TooExpensive:
					return "Trop cher";
				case ERPStore.Models.CancelQuoteReason.TooLong:
					return "Délai trop long";
				case ERPStore.Models.CancelQuoteReason.ProjectNotConcretized:
					return "Projet non concretisé";
				case ERPStore.Models.CancelQuoteReason.TradmarkNotRespected:
					return "Non respect des marques";
				case ERPStore.Models.CancelQuoteReason.AvailableQuantityInsufficient:
					return "Stock insuffisant";
				case ERPStore.Models.CancelQuoteReason.Other:
					return "Autre";
			}
			return "A definir";
		}

		public static string ToLocalizedName(this Models.QuoteStatus status)
		{
			if (status == ERPStore.Models.QuoteStatus.Waiting)
			{
				return "En cours";
			}
			else if (status == ERPStore.Models.QuoteStatus.WaitingPayement)
			{
				return "En attente de règlement";
			}
			else if (status == ERPStore.Models.QuoteStatus.ConvertedToOrder
				|| status == ERPStore.Models.QuoteStatus.ManualyConvertedToOrder)
			{
				return "Converti en commande";
			}
			else
			{
				return "Archivé";
			}
		}

		public static string ToLocalizedName(this Models.InvoiceStatus status)
		{
			switch (status)
			{
				case ERPStore.Models.InvoiceStatus.Unrecovered:
					return "Non réglée";
				case ERPStore.Models.InvoiceStatus.PartiallyRecovered:
					return "Règlement partiel";
				case ERPStore.Models.InvoiceStatus.FullyRecovered:
					return "Totalement réglée";
				case ERPStore.Models.InvoiceStatus.PartiallyLost:
				case ERPStore.Models.InvoiceStatus.FullyLost:
					return "Perte";
				case ERPStore.Models.InvoiceStatus.Processing:
					return "Règlement en traitement";
			}
			return "Inconnu";
		}



	}
}
